import Cookies from "js-cookie";

const state = {
    customerId: Cookies.get('customerId'),
    avatar: Cookies.get('customerId') ? Cookies.get('avatar') : ''
}

const getters = {
    getCutomerId() {
        return Cookies.get('customerId');
    },
    getAvatar() {
        return Cookies.get('customerId') ? Cookies.get('avatar') : '';
    }
}

const mutations = {
    SET_CUSTOMERID(state, id) {
        Cookies.set('customerId', id)
        state.customerId = id;
    },
    SET_AVATAR(state, url) {
        Cookies.set('avatar', url)
        state.avatar = url;
    },
    LOGOUT(state) {
        state.customerId = '';
        state.avatar = '';
        Cookies.remove('customerId');
        Cookies.remove('avatar');
    }
}

const actions = {
    setCustomerInfo({commit}, data) {
        commit("SET_CUSTOMERID", data.id);
        commit("SET_AVATAR", data.avatar)
    },
    logout({commit}) {
        commit("LOGOUT")
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}